package com.sec.android.app.myfiles.module.trash;

import android.app.FragmentManager;
import android.content.Context;

import com.samsung.android.sdk.slinkcloud.CloudGatewayFileBrowserUtils;
import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.module.abstraction.AbsFileOperationImp;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.operation.FileOperationArgs;
import com.sec.android.app.myfiles.operation.FileOperationException;
import com.sec.android.app.myfiles.operation.FileOperator;
import com.sec.android.app.myfiles.operation.ProgressListener;

import java.util.ArrayList;

/**
 * Created by gw8951.kim on 2016-12-08.
 */

public class TrashFileOperationImp extends AbsFileOperationImp {

    public TrashFileOperationImp(Context context, ProgressListener listener) {
        super(context, listener);
    }

    @Override
    protected boolean isSupport(FileRecord record) {
        return record.getStorageType() == FileRecord.StorageType.Trash;
    }

    @Override
    protected FileRecord _getUniqueFileRecord(FileRecord record) {
        return null;
    }

    @Override
    protected void _preOperation(FileOperator.Operation operationType) {

    }

    @Override
    protected void _postOperation(FileOperator.Operation operationType, FileOperationArgs args, int handledCount) {

    }

    @Override
    protected boolean _rename(FileRecord src, FileRecord dst) throws FileOperationException {
        return false;
    }

    @Override
    protected boolean _delete(FileRecord record) throws FileOperationException {
        int deviceId = ((TrashFileRecord) record).getDeviceId();
        String fileId = ((TrashFileRecord) record).getFileId();

        Log.d(this, "_delete : " + deviceId + " " + fileId);
        mProgresslistener.onProgressChanged(null, 0, 100);
        boolean ret = CloudGatewayFileBrowserUtils.getInstance(mContext).mrrControlCommand(deviceId, CloudGatewayFileBrowserUtils.REMOTE_TRASH_DELETE,
                null, fileId, null, null);

        if (ret) {
            mProgresslistener.onProgressChanged(null, 100, 100);
        }
        return ret;
    }

    @Override
    protected boolean _delete(ArrayList<FileRecord> recordList, FileOperator operator) throws FileOperationException {
        boolean bRet;
        if (recordList != null) {
            int size = recordList.size();
            if (size == 0) {
                bRet = true;
            } else {
                String[] selectedFile = new String[size];
                int index = 0;
                int deviceId = ((TrashFileRecord) recordList.get(0)).getDeviceId();
                for (FileRecord record : recordList) {
                    selectedFile[index++] = ((TrashFileRecord) record).getFileId();
                }

                mProgresslistener.onProgressChanged(null, 0, 100);
                bRet = CloudGatewayFileBrowserUtils.getInstance(mContext).mrrControlBatchCommand(deviceId, CloudGatewayFileBrowserUtils.REMOTE_TRASH_DELETE_BATCH, selectedFile, null);
            }
        } else {
            bRet = false;
        }

        if (bRet) {
            mProgresslistener.onProgressChanged(null, 100, 100);
        }

        return bRet;
    }

    @Override
    protected boolean isSupportCopyMove(FileRecord src, FileRecord dst) {
        return false;
    }

    @Override
    protected boolean isSupportRecursiveCopyMove() {
        return false;
    }

    @Override
    protected boolean _copy(ArrayList<FileRecord> src, FileRecord dst, FragmentManager fragmentManager, boolean singleFile, boolean dupCheck, FileOperator operator) throws FileOperationException {
        return false;
    }

    @Override
    protected boolean _copy(FileRecord src, FileRecord dst) throws FileOperationException {
        return false;
    }

    @Override
    protected boolean _move(ArrayList<FileRecord> src, FileRecord dst, FragmentManager fragmentManager, boolean singleFile, FileOperator operator, ArrayList<FileRecord> handledSrcList) throws FileOperationException {
        return false;
    }

    @Override
    protected boolean _move(FileRecord src, FileRecord dst) throws FileOperationException {
        return false;
    }

    @Override
    protected ArrayList<FileRecord> _getListInDirectory(FileRecord record) {
        return null;
    }

    @Override
    protected FileRecord _mkdir(FileRecord dst, String name) {
        return null;
    }

    @Override
    protected void makeScanLists(FileOperator.Operation op, ArrayList<String> pathList, ArrayList<String> fileList, FileOperationArgs args, int handledCount) {

    }
}
